package cn.quang.search.toolkit.component.items.impl.aggregation;

import org.apache.commons.lang3.StringUtils;

import java.util.List;
import java.util.stream.Collectors;

public enum ESAggregationConditionEnum {
    GROUP_BY("group by");

    private final String condition;

    ESAggregationConditionEnum(String condition) {
        this.condition = condition;
    }

    public String getCondition() {
        return condition;
    }

    /**
     * 该聚合函数需要在select中提供哪些列
     * @param columns 列
     * @return 聚合列
     */
    public String getAggregationColumnSql(List<String> columns){
        return StringUtils.join(columns.stream().map(column -> column + " as " + column).collect(Collectors.toSet()), ", ");
    }

    public String getAggregationConditionSql(List<String> columns){
        return this.condition + " " + StringUtils.join(columns, ", ");
    }
}
